package silo.dungeonbuddy;

import java.awt.Graphics;
import java.awt.Image;

public class Sprite
{
	/** The image to be drawn for this sprite */
	private Image image;
	
	public Sprite(Image image)
	{
		this.image = image;
	}
	
	public int getWidth()
	{
		return image.getWidth(null);
	}

	public int getHeight()
	{
		return image.getHeight(null);
	}
	
	public Image getImage()
	{
		return image;
	}
	
	public void draw(Graphics g,int x,int y,Start game,int sizeX,int sizeY,boolean onBoard)
	{
		if(onBoard)
		{
			try
			{
				g.drawImage(image,x+1,y+1,(int)Math.floor((game.getHeight()/game.getSquaresPerScreen())*sizeX)-1,(int)Math.floor((game.getHeight()/game.getSquaresPerScreen())*sizeY)-1,null);
			}catch(Exception e)
			{
				try
				{
					g.drawImage(SpriteStore.get().getSprite("sprites/defaultBack.png").getImage(),x+1,y+1,(int)Math.floor((game.getHeight()/game.getSquaresPerScreen())*sizeY)-1,(int)Math.floor((game.getHeight()/game.getSquaresPerScreen())*sizeY)-1,null);
				}catch (Exception e2)
				{
					System.out.println("ERROR: CODE 8");
				}
			}
		}else
		{
			try
			{
				g.drawImage(image,x,y,sizeX,sizeY,null);
			}catch(Exception e)
			{
				try
				{
					g.drawImage(SpriteStore.get().getSprite("sprites/defaultBack.png").getImage(),x,y,sizeX,sizeY,null);
				}catch (Exception e2)
				{
					System.out.println("ERROR: CODE 8");
				}
			}
		}
		//g.drawImage(image,x,y,null);
	}//draw
	
	public void draw(Graphics g,int x,int y,int sizeX,int sizeY,MapForm sender)
	{
		try
		{
			g.drawImage(image,x+1,y+1,(int)Math.floor((sender.getHeight()/sender.getSquaresPerScreen())*sizeX)-1,(int)Math.floor((sender.getHeight()/sender.getSquaresPerScreen())*sizeY)-1,null);
		}catch(Exception e)
		{
			try
			{
				g.drawImage(SpriteStore.get().getSprite("sprites/defaultBack.png").getImage(),x+1,y+1,(int)Math.floor((sender.getHeight()/sender.getSquaresPerScreen())*sizeY)-1,(int)Math.floor((sender.getHeight()/sender.getSquaresPerScreen())*sizeY)-1,null);
			}catch (Exception e2)
			{
				System.out.println("ERROR: CODE 8");
			}
		}
	}//draw
}